package com.xuwang.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.xuwang.Util.TableResult;
import com.xuwang.Util.WriteJson;
import com.xuwang.pojo.GovernmentPush;
import com.xuwang.pojo.GovernmentSupervisionPush;
import com.xuwang.service.GovernmentPushService;
import com.xuwang.service.impl.GovernmentPushServiceImpl;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (GovernmentPush)表控制层
 *
 * @author smallseven
 * @version 1.0
 * @since 2021-09-14 19:24:42
 */
@RestController
@RequestMapping("/governmentPush")
@Api(value = "(GovernmentPush)管理", tags = "(GovernmentPush)管理接口API")
@ApiResponses({
        @ApiResponse(code = 302, message = "临时重定向，被拦截器栏了"),
        @ApiResponse(code = 304, message = "缓存数据"),
        @ApiResponse(code = 400, message = "请求参数不完整或者错误"),
        @ApiResponse(code = 404, message = "找不到页面"),
        @ApiResponse(code = 405, message = "请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code = 406, message = "页面地址和接口名冲突"),
        @ApiResponse(code = 415, message = "请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code = 500, message = "后台服务逻辑错误")
})
public class GovernmentPushController {
    /**
     * 服务对象
     */
    @Resource
    private GovernmentPushService governmentPushService;

    /**
     * 政府推送日常信息
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/push", produces = "application/json;charset=UTF-8")
    @ResponseBody
    @ApiOperation(value = "政府推送内容", notes = "推送各种内容的咨询", httpMethod = "POST", response = String.class)
    public String push() throws Exception {
        TableResult<Map<Integer, List<GovernmentPush>>> result;
        result=governmentPushService.push();
        return WriteJson.getJson(result);
    }

    /**
     * 政府添加推送
     * @param governmentPush
     * @return
     * @throws JsonProcessingException
     */
    @RequestMapping(value = "/insertPush", produces = "application/json;charset=UTF-8")
    @ResponseBody
    @ApiOperation(value = "政府推送内容", notes = "推送各种内容的咨询", httpMethod = "POST", response = String.class)
    public String insertPush(@RequestBody  @ApiParam(name = "governmentPush",value = "governmentPush",required = true)GovernmentPush governmentPush) throws JsonProcessingException {
        TableResult<String> result;
        result=governmentPushService.insertPush(governmentPush);
        return WriteJson.getJson(result);
    }

    /**
     * 政府推送监管内容
     */
    @RequestMapping(value = "/SupervisionPush", produces = "application/json;charset=UTF-8")
    @ResponseBody
    @ApiOperation(value = "政府监督推送内容", notes = "推送各种监督内容的咨询", httpMethod = "POST", response = String.class)
    public String SupervisionPush() throws Exception {
        TableResult<Map<Integer, List<GovernmentSupervisionPush>>> result;
        result=governmentPushService.SupervisionPush();
        return WriteJson.getJson(result);
    }

    /**
     * 展示所有员工信息
     */
    @RequestMapping(value = "/getAllUser", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getAllUser() throws JsonProcessingException {
        TableResult<List> userList;
        userList=governmentPushService.getAllUser();
        return WriteJson.getJson(userList);
    }
}
